package com.ctshk.rpc.order.goods.mapper;

import com.ctshk.rpc.order.goods.base.CustomBaseMapper;
import com.ctshk.rpc.order.goods.dto.CommodityRecommendDTO;
import com.ctshk.rpc.order.goods.entity.CommodityRecommend;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品推荐表 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-13
 */
public interface CommodityRecommendMapper extends CustomBaseMapper<CommodityRecommend> {
	@Select("SELECT t.id,t.commodity_id,t.recommend_type,t.gmt_create,t.create_id,t.gmt_modified,t.modified_id,t.is_deleted "
			+ "FROM `ctshk-goods`.t_commodity_recommend t "
			+ "WHERE t.commodity_id = #{commodityId} AND t.is_deleted = 0")
	List<CommodityRecommend> findCommodityRecommendByCommodityId(@Param("commodityId") Long commodityId);

	// =============================== H5端 Start ===============================
	@Select("SELECT t.id,t.commodity_id,t.recommend_type,t.gmt_create,t.create_id,t.gmt_modified,t.modified_id,t.is_deleted "
			+ "FROM `ctshk-goods`.t_commodity_recommend t "
			+ "WHERE t.commodity_id = #{commodityId} AND t.is_deleted = 0")
	List<CommodityRecommend> findHtmlFiveCommodityRecommendByCommodityId(@Param("commodityId") Long commodityId);

	@Select({
			"<script>",
			"SELECT ",
			"t.id,t.commodity_id,t.recommend_type,t.gmt_create,t.create_id,t.gmt_modified,t.modified_id,t.is_deleted ",
			"FROM `ctshk-goods`.t_commodity_recommend t ",
			"WHERE t.is_deleted = 0 ",
			"<if test='commodityIds != null and commodityIds.size != 0 '>",
			"AND t.commodity_id IN ",
			"<foreach collection='commodityIds' item='id' open='(' separator=',' close=')'>",
			"#{id}",
			"</foreach>",
			"</if> ",
			"</script>"
	})
	List<CommodityRecommendDTO> findHtmlFiveCommodityRecommendByCommodityIds(@Param("commodityIds") List<Long> commodityIds);
	// =============================== H5端 End ===============================

}
